package io.renren.modules.mybog.service.impl;

import io.renren.modules.mybog.entity.CatePost;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.mybog.dao.CategoryDao;
import io.renren.modules.mybog.entity.CategoryEntity;
import io.renren.modules.mybog.service.CategoryService;
import org.springframework.util.StringUtils;


@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
        Object key = params.get("key");
         if(!StringUtils.isEmpty(key)){
             wrapper.eq("tltle",key);
         }
        IPage<CategoryEntity> page = this.page(
                new Query<CategoryEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public CategoryEntity findByNmae(String name) {
         QueryWrapper<CategoryEntity> wrapper=new QueryWrapper<>();
         wrapper.eq("tltle",name);
        CategoryEntity one = getOne(wrapper);
        return one;
    }

    @Override
    public List<CatePost> getListCatePost() {
        return baseMapper.getListCatePost();
    }

}